CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
CMAKE_POLICY(VERSION 2.8.9)

PROJECT(VT-EDITOR)

IF (NOT VERSION)
    SET(VERSION 0.1.0)
ENDIF()

STRING(REPLACE "." " " _VERSION ${VERSION})
SEPARATE_ARGUMENTS(_VERSION)
LIST(LENGTH _VERSION _LEN)
IF(NOT _LEN EQUAL 4 AND NOT _LEN EQUAL 3)
    MESSAGE(FATAL_ERROR "Version needs to be in the form MAJOR.MINOR.RELEASE[.BUILD]")
ENDIF()

LIST(GET _VERSION 0 VER_MAJOR)
LIST(GET _VERSION 1 VER_MINOR)
LIST(GET _VERSION 2 VER_RELEASE)
IF(_LEN EQUAL 4)
    LIST(GET _VERSION 3 VER_BUILD)
ELSE()
    SET(VER_BUILD 0)
ENDIF()

# where to look for cmake modules
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)

SET(PKG_NAME "vt-editor")
IF (WIN32)
    SET(PKG_DATADIR ".")
    SET(PKG_BINDIR ".")
    SET(LOCALEDIR ".")
    CONFIGURE_FILE(src/winver.h.in src/winver.h)
ELSE (WIN32)
    IF (NOT OSX AND NOT BEOS)
        OPTION(USE_X11 "Use X11 Clipboard functionality" ON)
    ENDIF ()
    SET(PKG_DATADIR ${CMAKE_INSTALL_PREFIX}/share/valyriatear CACHE PATH "Data dir")
    SET(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Locale dir")
    SET(PKG_BINDIR ${CMAKE_INSTALL_PREFIX}/bin CACHE PATH "Binary dir")
ENDIF (WIN32)

# The sub-folders to parse
ADD_SUBDIRECTORY(src)

# CPack installation part
If(UNIX)
    # Shortcut desktop file
    INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/vt-editor.desktop" DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
    # data files
    INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data" DESTINATION ${PKG_DATADIR} FILES_MATCHING PATTERN "*.png")
    # icon file
    INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/data/icons/program_icon.png"
            DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME vt-editor.png)
    # KDE/Gnome app center app data
    INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/vt-editor.appdata.xml"
            DESTINATION ${CMAKE_INSTALL_PREFIX}/share/appdata)
ENDIF()

SET(CPACK_PACKAGE_NAME "vt-editor")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Valyria Tear - Map Editor")
SET(CPACK_PACKAGE_VENDOR "Bertram")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSES" )
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "ValyriaTear-Map-Editor")
SET(CPACK_PACKAGE_VERSION_MAJOR ${VER_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VER_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VER_RELEASE})
IF(WIN32)
    SET(CPACK_NSIS_DISPLAY_NAME "Valyria Tear - Map Editor")
    SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/icons/program_icon.ico")
    SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/icons/program_icon.png") #TODO: use a bmp
    SET(CPACK_NSIS_URL_INFO_ABOUT "http://valyriatear.blogspot.com")
ENDIF()
INCLUDE(CPack)
